package logTest;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;




public class testcontent {
	static InputStreamReader bf = null;
	static BufferedReader br=null;

	static OutputStreamWriter osw = null;
	static BufferedWriter bw=null;
	
	static int kk;
	int i=1;
	int k=0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String content=null;
		String url1="C:/Users/JMC302/Desktop/java.txt";
		String url2="C:/Users/JMC302/Desktop/java2.txt";
		
		try {
			content=getSource(url1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
//		}
		
//		System.out.println(content);
//		if(null!=content){
//			String[] sss=content.split(",");
//			for(int i=0 ; i<sss.length;i++){
//				sss[i]=sss[i].trim();
//			}
//			
//			try {
//				sendSource(sss, url2);
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
			}finally{
				close();
			}
//		}
		


	}

	public static String getSource ( String url) throws Exception{
		File f=new File(url);
		if(!f.exists()){
			throw new notFind();
		}
		StringBuilder sb= new StringBuilder();

		bf=new InputStreamReader(new FileInputStream(url));
		br=new BufferedReader(bf);
		int i =0;
		while(br.ready()){
			String s=br.readLine();
			if(s.contains("name")&&s.contains("entry")){
//				sb.append(s);
				i++;
			}
			

		}
		System.out.println("有字段"+i+"个");
		return sb.toString();
	}
	
	public static void sendSource ( String[] sss ,String url) throws IOException{
		
		File f=new File(url);
		if(!f.exists()){
			f.createNewFile();
		}
		osw=new OutputStreamWriter(new FileOutputStream(url));
		bw=new BufferedWriter(osw);
		for(int i=0 ;i< sss.length;i++){
			bw.write(sss[i]);
			bw.newLine();
		}
		
	}
	
	
	public static void close (){
		
		try {
			if(null!=br){
				br.close();
			}
			if(null!=bf){
				bf.close();
			}
			
			if(null!=bw){
				bw.close();
			}
			if(null!=osw){
				osw.close();
			}
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}
	
	
}

class notFind extends RuntimeException{


	@Override
	public void printStackTrace() {
		// TODO Auto-generated method stub
		System.out.println("没有找到指定文件");
	}
	
	
	
}
